package com.kaiyidiannao.activity.myFavorites;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.*;
import com.kaiyidiannao.activity.SecondHandHouse.SecondHandHouseDetail;
import com.kaiyidiannao.activity.auction.AuctionDetailActivity;
import com.kaiyidiannao.activity.daydaycoupon.DdcDetailActivity;
import com.kaiyidiannao.activity.foodpalace.FoodPalaceDetail;
import com.kaiyidiannao.activity.foodpalace.PlayDetailActivity;
import com.kaiyidiannao.activity.messageInfo.MessageInfoDetail;
import com.kaiyidiannao.activity.secondhandcar.SecondHandCarDetail;
import com.kaiyidiannao.adapter.*;
import com.kaiyidiannao.common.BaseActionBarActivity;
import com.kaiyidiannao.common.pulltorefresh_view.DragListView;
import com.kaiyidiannao.common.util.NetworkConnected;
import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.*;
import com.kaiyidiannao.model.req.model.PostMyFavoritesLIst;
import com.kaiyidiannao.view.ActionBarView;
import com.taplinker.core.util.LogUtil;

import java.util.*;

/**
 * Created by wzg on 14-4-20.
 * 左侧我的收藏
 */
public class MyFavoritesActivity extends BaseActionBarActivity implements Observer {
    private ActionBarView actionBarView;
    private int index = 0;
    private FavoritesBean favoritesBean;
    private ProgressBar progressBar;
    private View no_content_view;//没有数据的布局对象
    private int currentPage = DataCenter.LISTVIEW_DEFAULT_PAGE;
    private ArrayList<DaydayCouponBean> ddList;
    private ArrayList<Auction> auctionList;
    private ArrayList<MessageBean> messageList;
    private ArrayList<SecondHandCar> secondHandCarList;
    private ArrayList<SecondHandHouse> secondHandHouseList;
    private ArrayList<PlayBean> playList;
    private String action = "delete";
    //最新分类样式
    private ListView categoryListView;
    private SimpleAdapter simpleAdapter;
    private List<Map<String, String>> data;
    private View itemParent;
    private DragListView listView;
    private BaseAdapter adapter = null;
    private CheckBox checkbox_category;
    private boolean isClose = true;
    private int typeid = DataCenter.myfacorites_id[0];
    private String[] categorys;
    private String userid = DataCenter.userLogin.get(0).getUserid();
    private int isFirst = 0;
    private int touchTime = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myfavorites);
        initView();

        DataCenter.getInstance().addObserver(this);
        findviews();
        initCategoryData();
        DataCenter.resultes = "";
        //默认的
        showCurrentProgressView();
        new PostMyFavoritesLIst(16, typeid + "", userid, DaydayCouponBean.class, currentPage,"16").execute();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        //重新请求数据
        showCurrentProgressView();
        requestData(currentPage);
    }

    private void findActionBar() {
        actionBarView = (ActionBarView) findViewById(R.id.infoActionBar);
        actionBarView.setTitle("我的天天惠");
        actionBarView.setTitleOnClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isClose = !isClose;
                if (isClose) {
                    closeTopBar();
                } else { //开启分类条
                    openTopBar();
                }
            }
        });
        actionBarView.setTitleIconIsUp(false);
        actionBarView.button_right_icon2.setVisibility(View.VISIBLE);
        actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.myfavorites_edit));
        actionBarView.button_right_icon2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NetworkConnected networkConnected = new NetworkConnected();
                if(auctionList == null || auctionList.size()==0&&ddList.size()==0&&messageList.size()==0&&secondHandCarList.size()==0&&secondHandHouseList.size()==0&&playList.size()==0){
                    Toast.makeText(MyFavoritesActivity.this,"暂无数据",Toast.LENGTH_SHORT).show();
                    return;
                }
                if (!networkConnected.isNetworkConnected(MyFavoritesActivity.this) && !networkConnected.isWifiConnected(MyFavoritesActivity.this) && !networkConnected.isMobileConnected(MyFavoritesActivity.this)) {
                    Toast.makeText(MyFavoritesActivity.this, "网路连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (touchTime == 1) { //隐藏删除按钮
                    hiddenDeleteButton();
                } else if (touchTime == -1) { //显示删除按钮
                    displayDeleteButton();
                }
            }
        });
        checkbox_category = actionBarView.checkBox;
        checkbox_category.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isShownTopBar()) {
                    closeTopBar();
                } else {
                    openTopBar();
                }
                checkbox_category.setChecked(isShownTopBar());
            }
        });
        actionBarView.setTitleIconIsUp(false);
    }

    /**
     * 隐藏删除按钮
     */
    private void hiddenDeleteButton() {
        actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.myfavorites_edit));
        touchTime = -1;
        for (int i = 1; i < listView.getChildCount() - 1; i++) {
            View view = listView.getChildAt(i);
            final ImageButton btDelete = (ImageButton) view.findViewById(R.id.btDelete);
            index = i - 1;
            if (view != null) {
                if (typeid == 56) { //信息框
                    Log.d("MyFavorites", typeid + "是 56");
                    TextView hotText = (TextView) view.findViewById(R.id.hotText);
                    TextView text = (TextView) view.findViewById(R.id.hot);
                    if (null != btDelete && hotText != null && text != null) {
                        btDelete.setVisibility(View.GONE);
                    }
                } else if (typeid == 66) { //拍拍乐
                    Log.d("MyFavorites", typeid + " 是 66");
                    ImageButton btn1 = (ImageButton) view.findViewById(R.id.btDelete);
                    if (btn1 != null) {
                        btn1.setVisibility(View.GONE);
                    }
                } else if (typeid == 4) {//天天惠
                    Log.d("MyFavorites", typeid + " 是 4");
                    ImageButton btn1 = (ImageButton) view.findViewById(R.id.btDelete);
                    ImageView daydaycoupon_favorites = (ImageView) view.findViewById(R.id.daydaycoupon_favorites);
                    if (btn1 != null && daydaycoupon_favorites != null) {
                        btn1.setVisibility(View.GONE);
                    }
                } else if (typeid == 65) { //拍拍乐
                    Log.d("MyFavorites", "typeid :" + typeid);
                    TextView popularity = (TextView) view.findViewById(R.id.popularity);
                    TextView textPop = (TextView) view.findViewById(R.id.textPop);
                    if (textPop != null && popularity != null && btDelete != null) {
                        btDelete.setVisibility(View.GONE);
                    }
                } else if (typeid == 64) {
                    TextView popularity = (TextView) view.findViewById(R.id.popularity);
                    TextView hits = (TextView) view.findViewById(R.id.hits);
                    btDelete.setVisibility(View.GONE);
                    popularity.setVisibility(View.VISIBLE);
                    hits.setVisibility(View.VISIBLE);
                } else if (typeid == 16 || typeid == 32) {
                    TextView storeAddress = (TextView) view.findViewById(R.id.storeAddress);
                    ImageButton foodPalaceLocation = (ImageButton) view.findViewById(R.id.foodPalaceLocation);
                    btDelete.setVisibility(View.GONE);
                    storeAddress.setVisibility(View.VISIBLE);
                    foodPalaceLocation.setVisibility(View.VISIBLE);
                }
            }
        }
    }

    /**
     * 显示删除按钮
     */
    private void displayDeleteButton() {
        actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.favorites_complete));
        DataCenter.tip = 1;
        int cont = listView.getChildCount();
        for (int i = 1; i < listView.getChildCount() - 1; i++) {
            View view = listView.getChildAt(i);
            final ImageButton btDelete = (ImageButton) view.findViewById(R.id.btDelete);
            index = i - 1;
            if (view != null) {
                Log.d("MyFavorites", i + "   " + typeid);
                if (typeid == 56) {
                    Log.d("MyFavorites", typeid + "是 56");
                    TextView hotText = (TextView) view.findViewById(R.id.hotText);
                    TextView text = (TextView) view.findViewById(R.id.hot);
                    btDelete.setVisibility(View.VISIBLE);
                } else if (typeid == 4) {
                    Log.d("MyFavorites", typeid + " 是 4");
                    ImageButton btn1 = (ImageButton) view.findViewById(R.id.btDelete);
                    ImageView daydaycoupon_favorites = (ImageView) view.findViewById(R.id.daydaycoupon_favorites);
                    if (btn1 != null && daydaycoupon_favorites != null) {
                        btn1.setVisibility(View.VISIBLE);
                    }
                } else if (typeid == 66) { //拍拍乐
                    Log.d("MyFavorites", typeid + " 是 66");
                    ImageButton btn1 = (ImageButton) view.findViewById(R.id.btDelete);
                    btn1.setVisibility(View.VISIBLE);
                } else if (typeid == 65) {
                    Log.d("MyFavorites", "typeid :" + typeid);
                    ImageView secondHandHouseImage = (ImageView) view.findViewById(R.id.secondHandHouseImage);
                    TextView secondHandHousePrice = (TextView) view.findViewById(R.id.secondHandHousePrice);
                    TextView textPrice = (TextView) view.findViewById(R.id.textPrice);
                    TextView square = (TextView) view.findViewById(R.id.square);
                    TextView ageLimit = (TextView) view.findViewById(R.id.ageLimit);
                    ImageButton callNum = (ImageButton) view.findViewById(R.id.callNum);
                    TextView callName = (TextView) view.findViewById(R.id.callName);
                    TextView popularity = (TextView) view.findViewById(R.id.popularity);
                    TextView textPop = (TextView) view.findViewById(R.id.textPop);
                    if (textPop != null && popularity != null && btDelete != null) {
                        textPop.setVisibility(View.GONE);
                        popularity.setVisibility(View.GONE);
                        btDelete.setVisibility(View.VISIBLE);
                    }
                } else if (typeid == 64) {
                    TextView popularity = (TextView) view.findViewById(R.id.popularity);
                    TextView hits = (TextView) view.findViewById(R.id.hits);
                    btDelete.setVisibility(View.VISIBLE);
                    popularity.setVisibility(View.GONE);
                    hits.setVisibility(View.GONE);
                } else if (typeid == 16 || typeid == 32 || typeid == 49) {
                    btDelete.setVisibility(View.VISIBLE);
                }
            }
            touchTime = 1;
        }
    }

    public void initView() {
        findActionBar();
    }

    private void initCategoryView() {
        categoryListView = (ListView) findViewById(R.id.category_listview);
        String[] from = new String[]{"img", "title"};
        int[] to = new int[]{R.id.category_icon, R.id.category_title};
        simpleAdapter = new SimpleAdapter(this, data, R.layout.category_listview_item, from, to);
        categoryListView.setAdapter(simpleAdapter);
        categoryListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if(!HttpUtils.isConnected()){
                    Toast.makeText(MyFavoritesActivity.this,"网络连接错误,请稍后重试",Toast.LENGTH_SHORT).show();
                    return;
                }

                itemParent = view;
                typeid = DataCenter.messageInfo_id[i];
                TextView textview = (TextView) itemParent.findViewById(R.id.category_title);
                textview.setTextColor(getResources().getColor(R.color.title_detail_color));
                simpleAdapter.notifyDataSetChanged();
                DataCenter.playTopBeansTopList.clear();
                currentPage = 1;
                actionBarView.title.setText(categorys[i]);
                isClose = true;
                closeTopBar();
                typeid = DataCenter.myfacorites_id[i];
                DataCenter.typeid = typeid;
                Log.d("Myfavorites typeid = ", typeid + "");

                //重新选择adapter
                selectAdapter();
                // 右上角的按钮恢复成编辑
                actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.myfavorites_edit));

                showCurrentProgressView();
                requestData(currentPage);

                Log.d("MyfavoritesActivity", typeid + "");
            }
        });
    }

    private void initCategoryData() {
        data = new ArrayList<Map<String, String>>();
        TreeMap<String, String> map = null;
        categorys = getResources().getStringArray(R.array.myfavorites);
        for (int i = 0; i < categorys.length; ++i) {
            map = new TreeMap<String, String>();
            if (i == 0) {
                map.put("img", "" + DataCenter.commmon_category_img[0]);
            } else {
                map.put("img", "" + DataCenter.commmon_category_img[1]);
            }
            map.put("title", categorys[i] + "...");
            data.add(map);
        }
    }

    private void findviews() {
        progressBar = (ProgressBar) findViewById(R.id.play_inner_progress_bar);
        no_content_view = findViewById(R.id.no_content_view);
        listView = (DragListView) findViewById(R.id.messageInfo_List);
        listView.setOnRefreshListener(new DragListView.OnRefreshLoadingMoreListener() {
            @Override
            public void onRefresh() {
                currentPage = DataCenter.LISTVIEW_DEFAULT_PAGE;
                requestData(currentPage);
            }

            @Override
            public void onLoadMore() {
                requestData(++currentPage);
            }
        });
    }

    /**
     * 选择模块的 adapter
     */
    private void selectAdapter() {
        if (typeid == 4) {
            adapter = new DaydaycouponAdapter(this, ddList);
        } else if (typeid == 66) {
            adapter = new AuctionAdapter(this, auctionList, true); //拍拍乐
        } else if (typeid == 65) {
            adapter = new SecondHandHouseAdapter(this, secondHandHouseList);
        } else if (typeid == 64) {//二手車
            adapter = new SecondHandCarAdapter(this, secondHandCarList);
        } else if (typeid == 56) {
            adapter = new MessageAdapter(this, messageList);
        } else if (typeid == 16) {//美食城
            adapter = new FoodPalaceAdapter(this, playList);
        } else if (typeid == 32) {//石子街
            adapter = new FoodPalaceAdapter(this, playList);
        } else if (typeid == 49) {//玩乐住
            adapter = new PalyListAdapter(this, playList);
        }
        listView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }

    /**
     * 收藏请求服务器数据
     *
     * @param currentPage
     */
    private void requestData(int currentPage) {
        if (typeid == 4) {
            new PostMyFavoritesLIst(16, typeid + "", userid, DaydayCouponBean.class, currentPage,"4").execute();
        } else if (typeid == 66) {
            new PostMyFavoritesLIst(17, typeid + "", userid, Auction.class, currentPage,"66").execute();
        } else if (typeid == 65) {
            new PostMyFavoritesLIst(28, typeid + "", userid, SecondHandHouse.class, currentPage,"65").execute();
        } else if (typeid == 64) {
            new PostMyFavoritesLIst(5, typeid + "", userid, SecondHandCar.class, currentPage,"64").execute();
        } else if (typeid == 56) {
            new PostMyFavoritesLIst(30, typeid + "", userid, MessageBean.class, currentPage,"56").execute();
        } else if (typeid == 16) {
            new PostMyFavoritesLIst(24, typeid + "", userid, PlayBean.class, currentPage,"16").execute();
        } else if (typeid == 32) {
            new PostMyFavoritesLIst(24, typeid + "", userid, PlayBean.class, currentPage,"32").execute();
        } else if (typeid == 49) {
            new PostMyFavoritesLIst(24, typeid + "", userid, PlayBean.class, currentPage,"49").execute();
        }
    }

    @Override
    public void update(Observable observable, Object data) {
        DataCenter.flag flag = (DataCenter.flag) data;
        if(!HttpUtils.isConnected()){
            listView.onRefreshComplete();
            listView.onLoadMoreComplete(false);
            //Toast.makeText(MyFavoritesActivity.this, "网络连接错误,请稍后重试", Toast.LENGTH_SHORT).show();
        }

        closeProgressDialog();

        if (flag == DataCenter.flag.GET_MYFAVORITES_SUCCESS
                || flag == DataCenter.flag.GET_MYFAVORITES_FAILED) { //获取我的收藏列表数据

            showCurrentDataView();
            listView.onRefreshComplete();
            listView.onLoadMoreComplete(false);
            if (flag == DataCenter.flag.GET_MYFAVORITES_SUCCESS) {
                Log.d(DataCenter.LOG_INFO, " DdcListActivity.update() -> SUCCESS");
                auctionList = DataCenter.auctionArrayList;
                playList = DataCenter.playBeanList;
                secondHandHouseList = DataCenter.secondHandHouses;
                secondHandCarList = DataCenter.secondHandCar;
                messageList = DataCenter.messageInfoList;
                ddList = DataCenter.daydayCouponBeanList;
                if (typeid == 4) {
                    adapter = new DaydaycouponAdapter(MyFavoritesActivity.this, ddList);
                    if (ddList == null || ddList.size() <= 0) {
                        showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                } else if (typeid == 66) {
                    adapter = new AuctionAdapter(MyFavoritesActivity.this, auctionList, true);
                    if (auctionList == null || auctionList.size() <= 0) {
                        showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                } else if (typeid == 65) {
                    adapter = new SecondHandHouseAdapter(MyFavoritesActivity.this, secondHandHouseList);
                    if (secondHandHouseList == null || secondHandHouseList.size() <= 0) {
                        showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                } else if (typeid == 64) {//二手车
                    adapter = new SecondHandCarAdapter(MyFavoritesActivity.this, secondHandCarList);
                    if (secondHandCarList == null || secondHandCarList.size() <= 0) {
                        showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                } else if (typeid == 56) {
                    adapter = new MessageAdapter(MyFavoritesActivity.this, messageList);
                    if (messageList == null || messageList.size() <= 0) {
                        showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                } else if (typeid == 16) {
                    adapter = new FoodPalaceAdapter(MyFavoritesActivity.this, playList);
                    if (playList == null || playList.size() <= 0) {
                        showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                } else if (typeid == 32) {
                    adapter = new FoodPalaceAdapter(MyFavoritesActivity.this, playList);
                    if (playList == null || playList.size() <= 0) {
                         showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                } else if (typeid == 49) {
                    adapter = new PalyListAdapter(MyFavoritesActivity.this, playList);
                    if (playList == null || playList.size() <= 0) {
                        showCurrentEmptyMsgView(getText(R.string.listview_msg_empty_fav).toString());
                    } else {
                        showCurrentDataView();
                        adapter.notifyDataSetChanged();
                    }
                }

                // 给listview每个item设置跳转
                if (isFirst == 0) {
                    adapter = new DaydaycouponAdapter(MyFavoritesActivity.this, DataCenter.daydayCouponBeanList);
                    listView.setAdapter(adapter);
                    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            setListviewOnItemClick(position);
                        }
                    });
                    isFirst = -1;
                }
            }

            if (flag == DataCenter.flag.GET_MYFAVORITES_FAILED) {
                if ((messageList == null || messageList.size() < 1)) {
                    no_content_view.setVisibility(View.VISIBLE);
                    listView.setVisibility(View.GONE);
                    progressBar.setVisibility(View.GONE);
                    ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(getText(R.string.listview_msg_error));
                } else {
                    no_content_view.setVisibility(View.GONE);
                }
                Log.d(DataCenter.LOG_ERROR, " PlayListActivity.update() -> FAILED");
            }

        }

        if (flag == DataCenter.flag.POST_DELETE_MESSAGE_SUCCESS) {
            String msg = "";
            if (DataCenter.code.equals(DataCenter.successFlag)) {
                if (typeid == 56) {
                    messageList.remove(DataCenter.position);
                    recoveButton(messageList);
                } else if (typeid == 66) {
                    auctionList.remove(DataCenter.position);
                    recoveButton(auctionList);
                } else if (typeid == 65) {
                    secondHandHouseList.remove(DataCenter.position);
                    recoveButton(secondHandHouseList);
                } else if (typeid == 64) {//二手車
                    secondHandCarList.remove(DataCenter.position);
                    recoveButton(secondHandCarList);
                } else if (typeid == 16) {
                    playList.remove(DataCenter.position);
                    recoveButton(playList);
                } else if (typeid == 32) {
                    playList.remove(DataCenter.position);
                    recoveButton(playList);
                } else if (typeid == 49) {
                    playList.remove(DataCenter.position);
                    recoveButton(playList);
                } else if (typeid == 4) {
                    ddList.remove(DataCenter.position);
                    recoveButton(ddList);
                }
                listView.setVisibility(View.GONE);
                android.os.Handler handler = new android.os.Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        listView.setVisibility(View.VISIBLE);
                        adapter.notifyDataSetChanged();
                    }
                }, 100);
                msg = "删除成功";

            } else {
                msg = "删除失败";
            }
            showToast(msg);
        }
    }

    /**
     * 恢复编辑按钮
     * 当list为空的时候，“完成”按钮变成”编辑“按钮
     */
    private void recoveButton(List list) {
        if(list.size() == 0) {
            actionBarView.button_right_icon2.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.myfavorites_edit));
        }
    }

    private void setListviewOnItemClick(int position) {
        Bundle bundleData = new Bundle();
        Class<?> classz = null;
        if (typeid == 4 && position < ddList.size() + 1) {
            bundleData.putSerializable("bean", ddList.get(position - 1));
            classz = DdcDetailActivity.class;
        } else if (typeid == 66 && position < auctionList.size() + 1) {
            bundleData.putSerializable("playBean", auctionList.get(position - 1));
            classz = AuctionDetailActivity.class;
        } else if (typeid == 65 && position < secondHandHouseList.size() + 1) {
            bundleData.putSerializable("bean", secondHandHouseList.get(position - 1));
            classz = SecondHandHouseDetail.class;
        } else if (typeid == 64 && position < secondHandCarList.size() + 1) {
            bundleData.putSerializable("playBean", secondHandCarList.get(position - 1));
            classz = SecondHandCarDetail.class;
        } else if (typeid == 56 && position < messageList.size() + 1) {
            bundleData.putSerializable("playBean", messageList.get(position - 1));
            classz = MessageInfoDetail.class;
        } else if ((typeid == 16 || typeid == 32) && position < playList.size() + 1) {
            bundleData.putSerializable("playBean", playList.get(position - 1));
            classz = FoodPalaceDetail.class;
        } else if (typeid == 49 && position < playList.size() + 1) {
            bundleData.putSerializable("playBean", playList.get(position - 1));
            classz = PlayDetailActivity.class;
        }
        if (classz != null) {
            Intent intent = new Intent(MyFavoritesActivity.this, classz);
            if (typeid == 4 && position < ddList.size() + 1) {
                intent.putExtra("itemid", ddList.get(position - 1).getItemid());
                intent.putExtra("catid", ddList.get(position - 1).getCatid());
            } else if (typeid == 66 && position < auctionList.size() + 1) {
                intent.putExtra("itemid", auctionList.get(position - 1).getItemid());
                intent.putExtra("catid", auctionList.get(position - 1).getCatid());
            } else if (typeid == 65 && position < secondHandHouseList.size() + 1) {
                intent.putExtra("itemid", secondHandHouseList.get(position - 1).getItemid());
                intent.putExtra("catid", secondHandHouseList.get(position - 1).getCatid());
            } else if (typeid == 64 && position < secondHandCarList.size() + 1) {
                intent.putExtra("catid", secondHandCarList.get(position - 1).getCatid());
                intent.putExtra("itemid", secondHandCarList.get(position - 1).getItemid());
            } else if (typeid == 56 && position < messageList.size() + 1) {
                intent.putExtra("catid", messageList.get(position - 1).getCatid());
                intent.putExtra("itemid", messageList.get(position - 1).getItemid());
            } else if ((typeid == 16 || typeid == 32 || typeid == 49) && position < playList.size() + 1) {
                intent.putExtra("itemid", playList.get(position - 1).getItemid());
                intent.putExtra("catid", playList.get(position - 1).getCatid());
            }
            DataCenter.myfav_position = position-1;
            DataCenter.PAGE = (position-1)/20+1;
            currentPage = (position-1)/20+1;
            intent.putExtras(bundleData);
            startActivity(intent);
        }
    }

    @Override
    protected void openTopBar() {
        actionBarView.setTitleIconIsUp(true);
        initCategoryView();
        categoryListView.setVisibility(View.VISIBLE);
        categoryListView.setAnimation(AnimationUtils.loadAnimation(this, R.anim.top_bar_in));
    }

    @Override
    protected void closeTopBar() {
        actionBarView.setTitleIconIsUp(false);
        categoryListView.setAnimation(AnimationUtils.loadAnimation(this, R.anim.top_bar_out));
        categoryListView.setVisibility(View.GONE);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LogUtil.d(DataCenter.LOG_INFO, MyFavoritesActivity.class.getSimpleName() + ".onDestroy");
        DataCenter.messageInfoList.clear();
        //删除观察者
        DataCenter.getInstance().deleteObserver(this);
    }

    @Override
    protected boolean isShownTopBar() {
        if (categoryListView == null) {
            return false;
        }
        return categoryListView.getVisibility() == View.VISIBLE;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
            if (isShownTopBar()) {
                actionBarView.checkBox.setChecked(false);
                isClose = true;
                closeTopBar();
                return false;
            }
        }
        return super.dispatchKeyEvent(event);
    }


    private void setFbUsersImage(final ListView listView, final ArrayList<MessageBean> fbUserArrayList) {
        // here am getting 0 ???
        for (int i = 0; i < listView.getChildCount(); i++) {
            ////
        }
    }

    /**
     * 显示列表数据
     */
    private void showCurrentDataView() {
        listView.setVisibility(View.VISIBLE);
        no_content_view.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
    }

    /**
     * 正在加载，隐藏列表
     */
    private void showCurrentProgressView() {
        listView.setVisibility(View.GONE);
        no_content_view.setVisibility(View.GONE);
        progressBar.setVisibility(View.VISIBLE);
    }

    /**
     * 提示没有数据
     */
    private void showCurrentEmptyMsgView(String msg) {
        listView.setVisibility(View.GONE);
        ((TextView) no_content_view.findViewById(R.id.notice_msg_tv)).setText(msg);
        no_content_view.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        closeProgressDialog();
    }
}
